clear
set more off

cap log close
log using "$logdir/rest_by_city.log", replace

use $fromsasdir/result if tp == 202103  & wg_amt > 0, clear
drop if wg_amt/num_emp <= 20 | num_emp == 0 

gen restaurant = naics3 == "722"
// get size distribution of restaurants

bys bin city: gegen m_rest = mean(restaurant)
gen weight = 1
qui replace weight = m_rest/(1-m_rest) if restaurant == 0


gen byte any_ertc = ertc > 0
gen byte any_amendment = ertc_amendment > 0
gen either = any_ertc | any_amendment
gcollapse any_ertc any_amendment either (count) n = firm_id [aw=weight], by(city restaurant) fast
list


sum either if city ~= "" [aw=n]

qui save $outdir/rest_by_city, replace

cap log close
